package cn.Mmovie.util;

import java.sql.*;

public class DbUtil {
    private static String url = "jdbc:mysql://localhost:3306/Mmovie?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8";
    private static String user = "root";
    private static String password = "123456";

    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() {
        Connection conn=null;
        try {
             conn = DriverManager.getConnection(url, user, password);
        }catch (SQLException e){
            e.printStackTrace();
        }
        return conn;
    }

    public static void close(ResultSet rs,PreparedStatement psmt,Connection conn) {
        try {
            if (rs != null) {
                rs.close();
            }if (psmt!=null){
                psmt.close();
            }if (conn!=null){
                conn.close();
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
